<template>
	<div class="cedian animate__animated animate__fadeIn">
    <!-- <div class="flexc" style="margin-bottom: 20px;">
      <div style="width: 100px; text-align: right;">设备名称</div>
      <div><el-input v-model="$route.query.shebei" style="width: 350px; margin-left: 30px;" placeholder="请输入设备名称" disabled></el-input></div>
    </div> -->

    <div class="flexc" style="margin-bottom: 20px;">
      <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>测点名称</div>
      <div><el-input v-model="all.dianName" style="width: 350px; margin-left: 30px;" placeholder="请输入测点名称"></el-input></div>
    </div>
    <div class="flexc" style="margin-bottom: 20px;">
      <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>测点类型</div>
      <div>
        <el-select v-model="all.dianType" style="width: 350px; margin-left: 30px;" disabled clearable filterable placeholder="请选择测点类型">
            <el-option label="动态量测点" :value="21"></el-option>
            <el-option label="转速量测点" :value="22"></el-option>
            <el-option label="工艺量测点" :value="23"></el-option>
        </el-select>
      </div>
    </div>

    <div class="flexc" style="margin-bottom: 20px;" v-if="all.dianType == 21">
      <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>测点方向</div>
      <div>
        <el-select v-model="all.cdFx" style="width: 350px; margin-left: 30px;"  clearable filterable placeholder="请选择测点方向">
            <el-option  v-for="item in xialaall.fangxiangilist" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </div>
    </div>

    <div class="flexc" style="margin-bottom: 20px;" v-if="all.dianType == 21">
      <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>定义组</div>
      <div>
        <el-select v-model="all.dingyiIds" style="width: 350px; margin-left: 30px;" multiple collapse-tags clearable filterable placeholder="请选择定义组">
            <el-option  v-for="item in dingyizulist" :key="item.dingyiId" :label="item.dingyiName" :value="item.dingyiId * 1"></el-option>
        </el-select>
      </div>
    </div>

    <div class="flexc" style="margin-bottom: 20px;" v-if="all.dianType == 22 || all.dianType == 23">
      <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>最小值</div>
      <div><el-input v-model="all.cdMin" type="number" onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))" style="width: 350px; margin-left: 30px;" placeholder="请输入最小值"></el-input></div>
    </div>

    <div class="flexc" style="margin-bottom: 20px;" v-if="all.dianType == 22 || all.dianType == 23">
      <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>最大值</div>
      <div><el-input v-model="all.cdMax" type="number" onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))" style="width: 350px; margin-left: 30px;" placeholder="请输入最大值"></el-input></div>
    </div>

    <div class="flexc" style="margin-bottom: 20px;" v-if="all.dianType == 23">
      <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>单位类型</div>
      <div>
        <el-select v-model="all.dwLx" style="width: 350px; margin-left: 30px;"  clearable filterable placeholder="请选择单位类型">
            <el-option  v-for="item in xialaall.danweileixing" :key="item.value" :label="item.label" :value="item.value * 1"></el-option>
        </el-select>
      </div>
    </div>

    <div class="flexc" style="margin-bottom: 20px;" v-if="all.dianType == 23">
      <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>工程单位</div>
      <div>
        <el-select v-model="all.gcDw" style="width: 350px; margin-left: 30px;"  clearable filterable placeholder="请选择工程单位">
            <el-option  v-for="item in xialaall.gongchengdanwei" :key="item.value" :label="item.label" :value="item.value * 1"></el-option>
        </el-select>
      </div>
    </div>

    <div style="padding-left: 130px;">
      <el-button type="primary" @click="add">确定</el-button>
    </div>

	</div>
</template>

<script>
  import { postxiala,getdian,updatedian,adddian,removedian,getdiyizu } from '@/api/xitong'
  import left from '../left.vue'
	export default {
		name: 'cedian',
    components:{
      left
    },
		data() {
			return {
        all:{
          dianId:"",
          "dianName":"",
          "dianType":"",
          "devId":"",

          "cdFx":"",
          "dingyiIds":[],

          cdMin:"",
          cdMax:"",

          dwLx:"",
          gcDw:""

        },
        list:[],
        // zuzhilist:[],
        shebeilist:[],
        search:{
          zuzhiid:"",
          shebeiID:"",
          page:1,
          page_size:20,
        },
        total:0,

        log:false,
        logtitle:"",

        xialaall:{
          fangxiangilist:"",
          gongchengdanwei:"",
          danweileixing:""
        },

        dingyizulist:""

			}
		},

		created() {
      Promise.all([this.getxialalist(),this.getxialalist2(),this.getxialalist3(),this.getdingyizu()]).then(()=>{
        if(this.$store.state.showwho.value){
            this.bianji(this.$store.state.showwho)
        }
        if(this.$store.state.showwho.what == 'add'){
            this.logshow()
        }
      })
		},
		mounted() {


		},
		methods: {
      getdingyizu:function(){
        return new Promise((res,rej)=>{
          getdiyizu().then(response => {
            this.dingyizulist = response.data
            res()
          })
        })
      },
      getxialalist:function(){
        let obj = {
          sysName:"系统配置",
          dictName:"动态量-测点方向",
          dictType:""
        }
        return new Promise((res,rej)=>{
          postxiala(obj).then(response => {
            this.xialaall.fangxiangilist = response.data
            res()
          })
        })
      },
      getxialalist2:function(){
        let obj2 = {
          sysName:"系统配置",
          dictName:"工艺量-工程单位",
          dictType:""
        }
        return new Promise((res,rej)=>{
          postxiala(obj2).then(response => {
            this.xialaall.gongchengdanwei = response.data
            res()
          })
        })

      },
      getxialalist3:function(){
        let obj3 = {
          sysName:"系统配置",
          dictName:"工艺量-单位类型",
          dictType:""
        }
        return new Promise((res,rej)=>{
          postxiala(obj3).then(response => {
            this.xialaall.danweileixing = response.data
            res()
          })
        })
      },
      shanchu:function(item){
        this.$confirm('此操作将永久删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {

          removedian(item.value).then(response => {
            this.$message.success('删除成功');
            this.$emit('gengxin')
          })
        })
      },
      bianji:function(item){
        this.logtitle = '修改测点'

        getdian(item.value).then(response => {
          item = response.data
          this.all = {
            "dianId": item.dianId,
            "dianName": item.dianName,
            "dianType": item.dianType,
            "devId": item.devId,
            "cdMin": item.cdMin,
            "cdMax": item.cdMax,
            "dwLx": item.dwLx,
            "gcDw": item.gcDw,
            "cdFx":item.cdFx,
            dingyiIds:item.dingyiIds
          }
        })
      },
      chushihua:function(){
        this.xialaall.fangxiangilist.forEach(item=>{
          if(item.mr){this.all.cdFx = item.value }
        })
        this.xialaall.danweileixing.forEach(item=>{
          if(item.mr){this.all.dwLx = parseInt(item.value) }
        })
        this.xialaall.gongchengdanwei.forEach(item=>{
          if(item.mr){this.all.gcDw = parseInt(item.value) }
        })
      },
      logshow:function(){
        this.logtitle = '新增测点'
        this.all = {
          "dianId": "",
          "dianName":"",
          "dianType":this.$store.state.showwho.type,
          "devId":this.$store.state.showwho.shebeiid,
          "cdFx":"",
          "dingyiIds":[]
        }
        this.chushihua()
      },
      add:function(){
        // if(this.all.dianType == 21){
        //   if(!this.all.cdFx || !this.all.dingyiIds){
        //     this.$message.error('请填写完整参数');
        //     return
        //   }
        // }
        // if(this.all.dianType == 22){
        //   if(!this.all.cdMin || !this.all.cdMax){
        //     this.$message.error('请填写完整参数');
        //     return
        //   }
        // }
        // if(this.all.dianType == 22){
        //   if(!this.all.cdMin || !this.all.cdMax || !this.all.dwLx || !this.all.gcDw){
        //     this.$message.error('请填写完整参数');
        //     return
        //   }
        // }


        if(this.all.dianId){
          updatedian(this.all).then(response => {
            this.$message.success('修改成功');
            this.$emit('gengxin')
          })
        }else{
          adddian(this.all).then(response => {
            this.$message.success('新增成功');
            this.$emit('gengxin')
          })
        }
      },


		}
	}
</script>


<style scoped >

</style>
